import logging.handlers
import os

BASE_PATH =os.path.dirname(__file__)

G_p=0

def init_log_config():
    logger = logging.getLogger()
    logger.setLevel("INFO")
    sh = logging.StreamHandler()
    filename = BASE_PATH + "/log/Yps.log"
    fh = logging.handlers.TimedRotatingFileHandler(filename,
           "midnight",1,7,encoding="utf-8")
    fmt = ("%(asctime)s %(levelname)s [%(name)s] "
           "[%(filename)s (%(funcName)s:%(lineno)d] - %(message)s")
    formatter = logging.Formatter(fmt)
    sh.setFormatter(formatter)
    fh.setFormatter(formatter)
    logger.addHandler(sh)
    logger.addHandler(fh)

if __name__ == '__main__':
    init_log_config()
    logging.debug("最低级别的日志")
    logging.info("这是一个消息级别的日志")
    logging.warning("这是一个警告")
    logging.error("出现bug了")
    logging.critical("系统马上就要奔溃了")